package cn.cloud.search.server.analyse_request.impl;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import cn.cloud.search.bean.query.QueryRequestInfo;
import cn.cloud.search.server.analyse_request.IAnalyseRequest;
import cn.cloud.utils.StringUtils;

public class AnalyseRequest implements IAnalyseRequest {
	
	private static final Logger log = Logger.getLogger(AnalyseRequest.class);

	public QueryRequestInfo analyse(HttpServletRequest request) {
		// TODO Auto-generated method stub
		QueryRequestInfo qri = null;
		String typeName = request.getParameter(QUERY_TYPE_NAME);
		String query_words = request.getParameter(QUERY_WORDS);
		
		String pageNo = request.getParameter(QUERY_PAGENO);
		log.info("search query params is:["+typeName+"-"+query_words+"]");
//		if(!StringUtils.isEmpty(query_words)){
//			try {
//				query_words=new String(query_words.getBytes("ISO8859-1"));
//			} catch (UnsupportedEncodingException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		if(!StringUtils.isEmpty(typeName)&&!StringUtils.isEmpty(query_words)){
			
			qri = new QueryRequestInfo(typeName,query_words,StringUtils.isEmpty(pageNo)?"0":pageNo);
		}
		return qri;
	}

}
